package com.tomhu.doservices;

import com.tomhu.util.ComparePriority;
import com.tomhu.util.Error;

/**
 * 处理括号的问题！！
 * 1. 第一次的结果没有被第二次运算的使用！！
 * 2. //第一次的结果被第二次的使用！！
 * @author tomhu
 *
 */
public class BracketServices {
	
	//operate1和operate
//	public static void changeOperate(String operate1, String operate2) {
//
//		if (operate2.equals("-") || operate2.equals("/")) {
//			changeWithEqualPriority(operate1);
//		}
//
//	}

	public static String replaceStrs(String operate, String placeStr) {
		if (operate.equals("+")) {
			placeStr = placeStr.replaceFirst("//+", "-");
		} else if (operate.equals("-")) {
			placeStr = placeStr.replaceFirst("-", "+");
		} else if (operate.equals("*")) {
			placeStr = placeStr.replaceFirst("//*", "/");
		} else if (operate.equals("/")) {
			placeStr = placeStr.replaceFirst("/", "*");
		} else {
			Error.showError();
		}
		return placeStr;
	}
	
	public static void dealBracket(
			String operate1, String operate2, String str1, String str2, String placeStrs) {
		
		if (ComparePriority.isLowPriority(operate1, operate2)) {
			placeStrs = "(" + placeStrs + ")";
		} else if (ComparePriority.isEqualPriority(operate1, operate2) && str1.equals(str2)) {
			if (operate2.equals("-") || operate2.equals("/")) {
				changeWithEqualPriority(operate1);
			}
		} else {
		}
	}
	
	public static void changeWithEqualPriority(String operate) {
		if (operate.equals("+")) {
			operate = "-";
		} else if (operate.equals("-")) {
			operate = "+";
		} else if (operate.equals("*")) {
			operate = "/";
		} else if (operate.equals("/")) {
			operate = "*";
		} else {
			Error.showError();
		}
	}
	
	public static void dealBracketString(
			String str, String choiceStr0, String choiceStr2, String strs, String replaceStr) {
		
		if (strs == null) {
			return ;
		}
		
		if (str.equals(choiceStr0)) {
			strs = strs.replaceFirst(choiceStr0, replaceStr);
		} else if (str.equals(choiceStr2)) {
			strs = strs.replaceFirst(choiceStr2, replaceStr);
		} else {
			Error.showError();
		}
	}
}
